package com.itheima.stock.process;

import com.itheima.stock.pojo.dto.PermissionsDTO;
import com.itheima.stock.pojo.vo.resp.PermissionsVO;
import org.apache.commons.compress.utils.Lists;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class DataProcess {

/*
    public void getPermission1(List<PermissionsDomain> permissions){
        if(permissions.isEmpty()){
            return;
        }
        for (PermissionsDomain permission : permissions) {
            List<PermissionsDomain> children = sysPermissionMapper.getPermissionsByMenusId(permission.getId());
            if(children.isEmpty()){
                permission.setChildren(Lists.newArrayList());
                continue;
            }
            permission.setChildren(children);
            getPermission(permission1.getChildren());
        }
    }
*/


    public List<PermissionsVO> getPermissions(List<PermissionsDTO> dtos, Long pid) {
        ArrayList<PermissionsVO> list = Lists.newArrayList();
        if (dtos.isEmpty()) {
            return list;
        }
        for (PermissionsDTO dto : dtos) {
            if (dto.getPid().equals(pid)) {
                    PermissionsVO vo = new PermissionsVO();
                    vo.setId(dto.getId());
                    vo.setIcon(dto.getIcon());
                    vo.setName(dto.getName());
                    vo.setPath(dto.getPath());
                    vo.setTitle(dto.getTitle());
                    vo.setChildren(getPermissions(dtos,dto.getId()));
                    list.add(vo);}
        }
        return list;
    }

    public List<PermissionsVO> getMenus(List<PermissionsDTO> dtos, Long pid) {
        ArrayList<PermissionsVO> list = Lists.newArrayList();
        if (dtos.isEmpty()) {
            return list;
        }
        for (PermissionsDTO dto : dtos) {
            if (dto.getPid().equals(pid)) {
                if(dto.getType()!=3){
                    PermissionsVO vo = new PermissionsVO();
                    vo.setId(dto.getId());
                    vo.setIcon(dto.getIcon());
                    vo.setName(dto.getName());
                    vo.setPath(dto.getPath());
                    vo.setTitle(dto.getTitle());
                    vo.setChildren(getMenus(dtos,dto.getId()));
                    list.add(vo);}
            }
        }
        return list;
    }
}
